Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to copy and move file with its attribute?

2 views
Skip to first unread message

oyster

unread,
Jul 19, 2010, 6:54:39 AM7/19/10
to pytho...@python.org
I mean writeonly, hidden, system and so on attributes

I use windows, but if possible, is there any method to do so in a
crossplatfrom way?

thanks

Peter Otten

unread,
Jul 19, 2010, 7:17:40 AM7/19/10
to
oyster wrote:

I can't check, but shutil.copy2() may do what you want.

Peter

Vlastimil Brom

unread,
Jul 19, 2010, 7:21:08 AM7/19/10
to pytho...@python.org
2010/7/19 oyster <lepto....@gmail.com>:

> I mean writeonly, hidden, system and so on attributes
>
> I use windows, but if possible, is there any method to do so in a
> crossplatfrom way?
>
> thanks
> --
> http://mail.python.org/mailman/listinfo/python-list
>

You may check to see several possibilities
http://timgolden.me.uk/python/win32_how_do_i/copy-a-file.html
Probably the shutil module might be appropriate for simple usecases.

hth,
vbr

MRAB

unread,
Jul 19, 2010, 12:57:31 PM7/19/10
to pytho...@python.org
Alban Nona wrote:
> Hello,
>
> About this one. I tried the os.system copy. But it seems I cant find the
> right syntax.
>
> *os.system ("xcopy /s %s %s" % (dirname1, dirname2))*
>
> This one seems to not working.
>
In what way doesn't it work?

If the names contain spaces then you need to quote them:

os.system('xcopy /s "%s" "%s"' % (dirname1, dirname2))

(It's easier to always quote them.)

If the destination doesn't exist then you need to add the "/i" flag:

os.system('xcopy /s /i "%s" "%s"' % (dirname1, dirname2))

> Is there anyway I can do this way:
>
> localpath= c:\
> networkpath=g:\
>
> os.system("copy localpath networkpath)
>
> I tried many variations, but still not working. Any help will apreciated :/
>

MRAB

unread,
Jul 19, 2010, 2:09:55 PM7/19/10
to pytho...@python.org
Alban Nona wrote:
> Hello Mrab,
>
> Thank you very much for this informations.
> Homever, Im still stuck with a problem:
>
> import os
> import sys
> import threading
> import shutil
>
> source= "C://Production//"
> dest= "D://Production//"
>
> os.system('xcopy /E /I /Q "%s" "%s"' % (source, dest))
>
>
> It seems that it wont copy the files
>
> File not found - //Production//
> 0 File(s) copied
>
> any idea of why its doing this please ?
>
[snip]
If you're using slashes then there's no need to double them. Also, you
don't need to end the folder names with slashes or backslashes (except
for root folders). That's what it doesn't like, apparently.

source = "C:/Production"
dest = "D:/Production"

os.system('xcopy /E /I /Q "%s" "%s"' % (source, dest))

Nobody

unread,
Jul 19, 2010, 2:46:55 PM7/19/10
to
On Mon, 19 Jul 2010 17:57:31 +0100, MRAB wrote:

>> About this one. I tried the os.system copy. But it seems I cant find the
>> right syntax.
>>
>> *os.system ("xcopy /s %s %s" % (dirname1, dirname2))*
>>
>> This one seems to not working.
>>
> In what way doesn't it work?
>
> If the names contain spaces then you need to quote them:
>
> os.system('xcopy /s "%s" "%s"' % (dirname1, dirname2))

No, you need to use subprocess.call() instead of os.system().

If you absolutely must use os.system() for some reason, at least quote the
arguments correctly. If you want to know how to do this, look at the
subprocess.py source code (hint: it's not as simple as the above suggests).


Message has been deleted
0 new messages